local tiaozhan = fk.CreateSkill {
  name = "kl__tiaozhan",
  tags = { Skill.Compulsory, Skill.AttachedKingdom },
  attached_kingdom = {"shu"},
}

Fk:loadTranslationTable{
  ["kl__tiaozhan"] = "挑战",
  [":kl__tiaozhan"] = "蜀势力技，锁定技，你视为拥有标准+EX和军争牌堆所有装备牌的效果（坐骑不可叠加）。",

  ["$kl__tiaozhan1"] = "我有一计，可使汉室幽而复明。",
}

tiaozhan:addEffect("distance", {
  correct_func = function(self, from, to)
    if from:hasSkill(tiaozhan.name) then
      return -1
    end
    if to:hasSkill(tiaozhan.name) then
      return 1
    end
  end,
})

tiaozhan:addEffect("atkrange", {
  correct_func = function(self, from, to)
    if from:hasSkill(tiaozhan.name) then
      return 4
    end
  end,
})

tiaozhan:addEffect(fk.SkillEffect, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(tiaozhan.name) then
      local names = { "standard_cards", "maneuvering" }
      return data.skill:isEquipmentSkill(player) and table.contains(names, data.skill.package.extensionName)
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local all = {"special", "drawcard", "control", "offensive", "support", "defensive", "negative", "masochism"}
    player:broadcastSkillInvoke(tiaozhan.name)
    player.room:notifySkillInvoked(player, tiaozhan.name, table.random(all))
  end,
})

tiaozhan:addAcquireEffect(function (self, player, is_start)
    local room = player.room
    local names = { "standard_cards", "maneuvering" }
    local cards = {}
    for _, card in ipairs(Fk.cards) do
      if card.type == Card.TypeEquip and card.sub_type ~= Card.SubtypeDefensiveRide and card.sub_type ~= Card.SubtypeOffensiveRide
      and table.contains(names, card.package.extensionName) then
        table.insertIfNeed(cards, card.name)
      end
    end
    local all = {}
    for _, name in ipairs(cards) do
      local card = Fk:cloneCard(name)---@cast card EquipCard
      local skills = card:getEquipSkills(player)
      for _, s in ipairs(skills) do
        if not player:hasSkill(s, true) then
          table.insertIfNeed(all, s.name)
          room:handleAddLoseSkills(player, s.name, nil, false, true)
        end
      end
    end
    room:setPlayerMark(player, tiaozhan.name, all)
end)

tiaozhan:addLoseEffect(function (self, player, is_death)
    local room = player.room
    local all = player:getTableMark(tiaozhan.name)
    for _, name in ipairs(all) do
      if player:hasSkill(name, true) then
        room:handleAddLoseSkills(player, "-"..name, nil, false, true)
      end
    end
end)

--[[
--八卦阵
local spec = function (self, event, target, player, data)
  local room = player.room
  room:broadcastPlaySound("./packages/standard_cards/audio/card/eight_diagram")
  room:setEmotion(player, "./packages/standard_cards/image/anim/eight_diagram")
  local skill = Fk.skills["#eight_diagram_skill"]
  skill:use(event, target, player, data)
end
tiaozhan:addEffect(fk.AskForCardUse, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(tiaozhan.name) and not player:isFakeSkill(self) and
      (data.cardName == "jink" or (data.pattern and Exppattern:Parse(data.pattern):matchExp("jink|0|nosuit|none"))) and
      Fk.skills["#eight_diagram_skill"] ~= nil and Fk.skills["#eight_diagram_skill"]:isEffectable(player)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = tiaozhan.name, })
  end,
  on_use = spec,
})
tiaozhan:addEffect(fk.AskForCardResponse, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(tiaozhan.name) and not player:isFakeSkill(self) and
      (data.cardName == "jink" or (data.pattern and Exppattern:Parse(data.pattern):matchExp("jink|0|nosuit|none"))) and
      #player:getEquipments(Card.SubtypeArmor) == 0 and
      Fk.skills["#eight_diagram_skill"] ~= nil and Fk.skills["#eight_diagram_skill"]:isEffectable(player)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = tiaozhan.name, })
  end,
  on_use = spec,
})

tiaozhan:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(tiaozhan.name) and
      data.card and data.card.trueName == "slash" and not data.to.dead and
      Fk.skills["#qinggang_sword_skill"]:isEffectable(player)
  end,
  on_use = function (self, event, target, player, data)
    Fk.skills["#qinggang_sword_skill"]:doCost(event, target, player, data)
  end,
})
--]]


return tiaozhan
